package manager.auth.controller;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import manager.auth.service.UserPermissionService;
import manager.auth.vo.*;
import manager.config.RequiredPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping(value = {"/admin/sys"})
public class UserPermissionController {
    @Autowired
    private UserPermissionService userPermissionService;

    /**
     * 分页查询用户列表
     *
     * @param sysUserConditionVO
     * @return
     */
    @RequiredPermission(module="sysUser",code = "listPage")
    @RequestMapping(value = "/user/page/list", method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(notes = "获取商城用户信息", value = "query sys user")
    public PageInfo<SysUserVO> selectPageUser(@RequestBody SysUserConditionVO sysUserConditionVO) {
        PageInfo<SysUserVO> pageVO = userPermissionService.selectPageUser(sysUserConditionVO);
        return pageVO;
    }

    /**
     * 分页查询角色列表
     */
    @RequiredPermission(module="sysRole",code = "listPage")
    @RequestMapping(value = "/role/page/list", method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(notes = "获取商城用户信息", value = "query sys role")
    public PageInfo<SysRoleVO> selectPageRole(@RequestBody SysRoleConditionVO sysRoleCOnditionVO) {
        PageInfo<SysRoleVO> pageVO = userPermissionService.selectPageRole(sysRoleCOnditionVO);
        return pageVO;
    }

    /**
     * 分页查询权限列表
     */
    @RequiredPermission(module="sysPermission",code = "list")
    @RequestMapping(value = "/permission/page/list", method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(notes = "获取商城用户信息", value = "query sys role")
    public List<SysPermissionVO> selectPagePermission(@RequestBody SysPermissionConditionVO sysPermissionConditionVO) {
        List<SysPermissionVO> permissionList = userPermissionService.selectPagePermission(sysPermissionConditionVO);
        return permissionList;
    }

    /**
     * 分页查询用户列表
     *
     * @param sysUserVO
     * @return
     */
    @RequiredPermission(module="sysUser",code = "list")
    @RequestMapping(value = "/user/list", method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(notes = "获取商城用户信息", value = "query sys user")
    public List<SysUserVO> selectUser(@RequestBody SysUserVO sysUserVO) {
        List<SysUserVO> users = userPermissionService.selectUser(sysUserVO);
        return users;
    }

    /**
     * 分页查询角色列表
     */
    @RequiredPermission(module="sysUser",code = "list")
    @RequestMapping(value = "/role/list", method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(notes = "获取商城用户信息", value = "query sys role")
    public List<SysRoleVO> selectRole(@RequestBody SysRoleVO sysRoleVO) {
        List<SysRoleVO> roles = userPermissionService.selectRole(sysRoleVO);
        return roles;
    }

    /**
     * 分页查询权限列表d
     */
    @RequiredPermission(module="permission",code = "list")
    @RequestMapping(value = "/permission/list", method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(notes = "获取商城用户信息", value = "query sys role")
    public List<SysPermissionVO> selectPermission(@RequestBody SysPermissionVO sysPermissionVO) {
        List<SysPermissionVO> permissions = userPermissionService.selectPermission(sysPermissionVO);
        return permissions;
    }

    /**
     * 添加用户
     */
    @RequiredPermission(module="sysUser",code = "add")
    @RequestMapping(value = "/user/add", method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(notes = "获取商城用户信息", value = "query sys role")
    public void addUser(@RequestBody SysUserVO sysUserVO) {
        userPermissionService.addUser(sysUserVO);
    }
    /**
     * 修改用户
     */
    @RequiredPermission(module="sysUser",code = "update")
    @RequestMapping(value = "/user/update", method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(notes = "获取商城用户信息", value = "update user")
    public void updateUser(@RequestBody SysUserVO sysUserVO) {
        userPermissionService.updateUser(sysUserVO);
    }

    /**
     * 删除用户
     */
    @RequiredPermission(module="sysUser",code = "delete")
    @RequestMapping(value = "/user/delete", method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(notes = "获取商城用户信息", value = "delete user")
    public void deleteUser(@RequestBody List<SysUserVO> sysUserList) {
        userPermissionService.deleteUser(sysUserList);
    }

    /**
     * 添加角色
     */
    @RequiredPermission(module="sysRole",code = "add")
    @RequestMapping(value = "/role/add", method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(notes = "获取商城用户信息", value = "query sys role")
    public void addRole(@RequestBody SysRoleVO sysRoleVO) {
        userPermissionService.addRole(sysRoleVO);
    }

    /**
     * 添加角色
     */
    @RequiredPermission(module="sysRole",code = "update")
    @RequestMapping(value = "/role/update", method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(notes = "获取商城用户信息", value = "update user")
    public void updateRole(@RequestBody SysRoleVO sysUserVO) {
        userPermissionService.updateRole(sysUserVO);
    }

    /**
     * 删除角色
     */
    @RequiredPermission(module="sysRole",code = "delete")
    @RequestMapping(value = "/role/delete", method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(notes = "获取商城用户信息", value = "delete user")
    public void deleteRole(@RequestBody List<SysRoleVO> sysRoleList) {
        userPermissionService.deleteRole(sysRoleList);
    }

    /**
     * 添加权限
     */
    @RequiredPermission(module="sysPermission",code = "add")
    @RequestMapping(value = "/permission/add", method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(notes = "获取商城用户信息", value = "query sys role")
    public void addPermission(@RequestBody SysPermissionVO sysPermissionVO) {
        userPermissionService.addPermission(sysPermissionVO);
    }

    /**
     * 修改权限
     */
    @RequiredPermission(module="sysPermission",code = "update")
    @RequestMapping(value = "/permission/update", method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(notes = "获取商城用户信息", value = "update user")
    public void updatePermission(@RequestBody SysPermissionVO sysPermissionVO) {
        userPermissionService.updatePermission(sysPermissionVO);
    }

    /**
     * 删除权限
     */
    @RequiredPermission(module="sysPermission",code = "delete")
    @RequestMapping(value = "/permission/delete", method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(notes = "获取商城用户信息", value = "delete user")
    public void deletePermission(@RequestBody List<SysPermissionVO> sysPermissionList) {
        userPermissionService.deletePermission(sysPermissionList);
    }

    /**
     * 建立用户和角色关系
     */
    @RequiredPermission(module="sysUser",code = "addUserRole")
    @RequestMapping(value = "/user/role/add", method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(notes = "建立用户角色关系", value = "delete user")
    public void addUserRoleRls(@RequestBody List<SysUserRoleVO> sysUserRoleVO) {
        userPermissionService.addUserRoleRls(sysUserRoleVO);
    }

    /**
     * 添加角色和权限
     */
    @RequiredPermission(module="role",code = "addRolePermission")
    @RequestMapping(value = "/role/permission/add", method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(notes = "建立用户角色关系", value = "delete user")
    public void addRolePermissionRls(@RequestBody List<SysRolePermissionVO> sysRolePermissionVO) {
        userPermissionService.addRolePermissionRls(sysRolePermissionVO);
    }

    /**
     * 删除角色权限关系
     * @param sysRolePermissionVO
     */
    @RequestMapping(value = "/role/permission/delete", method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(notes = "删除用户角色关系", value = "delete role permission")
    public void deleteRolePermissionRls(@RequestBody SysRolePermissionVO sysRolePermissionVO) {
        userPermissionService.deleteRolePermissionRls(sysRolePermissionVO);
    }

    /**
     * 删除用具角色关系
     */
    @RequestMapping(value = "/role/user/delete", method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(notes = "删除用户角色关系", value = "delete role permission")
    @RequiredPermission(module="sysRoleUser",code = "delete")
    public void deleteRolePermissionRls(@RequestBody SysUserRoleVO sysUserRoleVO) {
        userPermissionService.deleteUserRoleRls(sysUserRoleVO);
    }

    /**
     * 查看用户角色
     */
    @RequestMapping(value = "/user/role/get", method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(notes = "查询用户角色", value = "delete user")
    @RequiredPermission(module="sysUser",code = "getUserRole")
    public List<SysUserRoleVO> getUserRoleRls(@RequestBody SysUserRoleVO sysUserRoleVO) {
        List<SysUserRoleVO> userRoles = userPermissionService.getUserRoleRls(sysUserRoleVO);
        return userRoles;
    }

    /**
     * 查看角色权限
     */

    @RequestMapping(value = "/role/permission/get", method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(notes = "查询权限", value = "delete user")
    @RequiredPermission(module="sysUser",code = "getPermission")
    public List<SysPermissionVO> getRolePermissionRls(@RequestBody SysRolePermissionVO sysRolePermissionVO) {
        return userPermissionService.getRolePermissionRls(sysRolePermissionVO);
    }
    /**
     * 查询用户权限,不需要权限校验
     */
    @RequestMapping(value = "/get/permissionByUserId", method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(notes = "查询用户权限", value = "delete user")
    public List<SysPermissionVO> getPermissionByUserId() {
          return userPermissionService.getPermissionByUserId();
    }
    /**
     * 修改用户密码,修改密码不需要权限控制
     */
    @RequestMapping(value = "user/password/update", method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(notes = "建立用户角色关系", value = "delete user")
    public void updatePassword(@RequestBody SysUserVO sysUserVO) {
        userPermissionService.updateUser(sysUserVO);
    }
    //初始化密码权限
    @RequiredPermission(module="sysUser",code = "initPassword")
    @RequestMapping(value = "user/password/init", method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(notes = "初始化用用户密码", value = "delete user")
    public void initPassword(@RequestBody SysUserVO sysUserVO) {
        userPermissionService.initPassword(sysUserVO);
    }

}
